<%= stylesheet_link_tag "components/_photo" %>

<script type="text/javascript" charset="utf-8">
    $(function () {
        var sharedPhoto = root.getWidgetById("shared-photo");

        // 点击即跳转
        sharedPhoto.on("keydown", function (e) {
            e =e || window.event;
            var keyValue = e.which || e.keyCode;
            if (keyValue === 13) {
                var dataset = e.target.con.dataset;
                if (dataset.href) {
                    window.location.href = e.target.con.dataset.href;
                } else {
                    var photoFavText = $("#photo-fav-text");
                    $.ajax({
                        url: "<%= users_toggle_playlist_path %>" + "?klass=" + dataset.klass + "&id=" + dataset.id,
                        dataType: "text",
                        type: "POST",
                        success: function (data) {
                            if (data === "is_added") {
                                photoFavText.text("取消收藏");
                            } else {
                                photoFavText.text("收藏歌单");
                            }
                        }
                    }).done(function () {
                        FocusEngine.render(); // 重新渲染组件树
                    });
                }
            }
        });
    });
</script>

<div id="shared-photo"
     class="photo"
     fe-role="Switch"
>
  <%= image_tag(item_image_url(item), class: "photo-image", onerror: "this.onerror=null;this.src='/singer_default.jpg';") %>
  <div class="photo-title"><%= item[:name] %></div>
  <div class="photo-subtitle"><%= item[:description] %></div>

  <div data-klass="<%= item.class %>"
       data-id="<%= item.id %>"
       class="photo-fav"
       fe-role="Widget"
  >
    <%= image_tag("icons/white_heart.png", class: "photo-fav-icon photo-fav-icon-white") %>
    <%= image_tag("icons/green_heart.png", class: "photo-fav-icon photo-fav-icon-green") %>
    <span id="photo-fav-text" class="photo-fav-text"><%= favs.exists?(item.id) ? "取消收藏" : "收藏歌单" %></span>
  </div>

  <% if cookies[:order_type] == "free" %>
    <div data-href="<%= platform_order_path(original_fullpath: request.original_fullpath) %>"
         class="photo-vip"
         fe-role="Widget"
    >
      <%= image_tag("icons/white_diamond.png", class: "photo-vip-icon photo-vip-icon-white") %>
      <%= image_tag("icons/green_diamond.png", class: "photo-vip-icon  photo-vip-icon-green") %>
      <div class="photo-vip-text">开通会员</div>
    </div>
  <% end %>
</div>
